package com.pgybook.db.entity.mapper;

import org.springframework.stereotype.Repository;
import com.pgybook.db.entity.domain.BookInstance;
import com.pgybook.db.entity.domain.BookInstanceEx;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

@Repository
public interface BookInstanceMapper {
    int countByExample(BookInstanceEx example);

    int deleteByExample(BookInstanceEx example);

    @Delete({
            "delete from bookinstance",
            "where INSTANCEID = #{instanceid,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long instanceid);

    @Insert({
            "insert into bookinstance (BOOKID, LIBID, ",
            "PROVIDERID, NAME, ",
            "ISBN, BOOKNO, POSITIONCODE, ",
            "STATUS, STOPFLAG, PREORDERFLAG, ",
            "PREORDERUSER, PREORDERTIME, ",
            "CRTTIME, UPDTIME, ",
            "LATESTORDER, CRTSTAFF, ",
            "UPDSTAFF)",
            "values (#{bookid,jdbcType=BIGINT}, #{libid,jdbcType=INTEGER}, ",
            "#{providerid,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, ",
            "#{isbn,jdbcType=VARCHAR}, #{bookno,jdbcType=VARCHAR}, #{positioncode,jdbcType=VARCHAR}, ",
            "#{status,jdbcType=INTEGER}, #{stopflag,jdbcType=BIT}, #{preorderflag,jdbcType=BIT}, ",
            "#{preorderuser,jdbcType=INTEGER}, #{preordertime,jdbcType=TIMESTAMP}, ",
            "#{crttime,jdbcType=TIMESTAMP}, #{updtime,jdbcType=TIMESTAMP}, ",
            "#{latestorder,jdbcType=BIGINT}, #{crtstaff,jdbcType=INTEGER}, ",
            "#{updstaff,jdbcType=INTEGER})"
    })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "instanceid", before = false, resultType = Long.class)
    int insert(BookInstance record);

    int insertSelective(BookInstance record);

    List<BookInstance> selectByExample(BookInstanceEx example);

    @Select({
            "select",
            "INSTANCEID, BOOKID, LIBID, PROVIDERID, NAME, ISBN, BOOKNO, POSITIONCODE, STATUS, ",
            "STOPFLAG, PREORDERFLAG, PREORDERUSER, PREORDERTIME, CRTTIME, UPDTIME, LATESTORDER, ",
            "CRTSTAFF, UPDSTAFF",
            "from bookinstance",
            "where INSTANCEID = #{instanceid,jdbcType=BIGINT}"
    })
    @ResultMap("BaseResultMap")
    BookInstance selectByPrimaryKey(Long instanceid);

    int updateByExampleSelective(@Param("record") BookInstance record, @Param("example") BookInstanceEx example);

    int updateByExample(@Param("record") BookInstance record, @Param("example") BookInstanceEx example);

    int updateByPrimaryKeySelective(BookInstance record);

    @Update({
            "update bookinstance",
            "set BOOKID = #{bookid,jdbcType=BIGINT},",
            "LIBID = #{libid,jdbcType=INTEGER},",
            "PROVIDERID = #{providerid,jdbcType=INTEGER},",
            "NAME = #{name,jdbcType=VARCHAR},",
            "ISBN = #{isbn,jdbcType=VARCHAR},",
            "BOOKNO = #{bookno,jdbcType=VARCHAR},",
            "POSITIONCODE = #{positioncode,jdbcType=VARCHAR},",
            "STATUS = #{status,jdbcType=INTEGER},",
            "STOPFLAG = #{stopflag,jdbcType=BIT},",
            "PREORDERFLAG = #{preorderflag,jdbcType=BIT},",
            "PREORDERUSER = #{preorderuser,jdbcType=INTEGER},",
            "PREORDERTIME = #{preordertime,jdbcType=TIMESTAMP},",
            "CRTTIME = #{crttime,jdbcType=TIMESTAMP},",
            "UPDTIME = #{updtime,jdbcType=TIMESTAMP},",
            "LATESTORDER = #{latestorder,jdbcType=BIGINT},",
            "CRTSTAFF = #{crtstaff,jdbcType=INTEGER},",
            "UPDSTAFF = #{updstaff,jdbcType=INTEGER}",
            "where INSTANCEID = #{instanceid,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(BookInstance record);
}
